<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>收货地址</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@beta/lib/index.css">
		<!-- 引入组件 -->
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vant@beta/lib/vant.min.js"></script>
		<script type="application/javascript" src="../js/flexible.debug.js"></script>
		<script type="application/javascript" src="../js/flexible_css.debug.js"></script>
		<script type="text/javascript" src="../js/area.js"></script>
		<script type="text/javascript" src="../js/jquery-1.10.1.min.js"></script>
		<script type="text/javascript" src="../js/querystring.min.js"></script>
		<script type="text/javascript" src="../js/cfg.js"></script>
		<link rel="stylesheet" href="../css/layout.css">
	</head>
	<body>
		<div id="app" v-cloak>
			<div class="backgroundcolorfff content height100">
				<van-address-edit :area-list="areaList" show-set-default show-search-result :search-result="searchResult"
				 :address-info="addressInfo" @save="onSave" save-button-text="保存收货地址"/>
			</div>
		</div>
		<script>
			var vant = window.vant;
			var qsd = querystring.parse();
			var cfg = new AppCfg().init({
				isDebug: false,
			});
			var addressid = qsd.addressid || '';
			Vue.use(vant);
			new Vue({
				el: '#app',
				data: {
					addressid: addressid,
					searchResult: [],
					areaList: [],
					addressInfo: {}
				},
				created: function() {
					this.areaList = areaList;
					this.checkaddress();
				},
				methods: {
					checkPhone:function(e){
						alert(e)
						var phonereg = /^1(3|4|5|6|7|8|9)\d{9}$/; //手机号验证规则
						if (!e.match(phonereg)) {
							vant.Toast('请输入正确的手机号')
							// return false;
						}else{
							// window.location.href = "address.html?userid=" + qsd.userid
						}
					},
					checkaddress: function() {
						var that = this;
						var parm = {
							address_id: addressid
						}
						cfg.majaxAction("getAddressById", parm, function(res) {
							if (res.data) {
								var addressInfo = {
									id: res.data.id,
									name: res.data.ad_consignee,
									tel: res.data.ad_phone,
									province: res.data.ad_province,
									city: res.data.ad_city,
									county:'',
									areaCode:res.data.ad_area,
									addressDetail: res.data.ad_detail_address,
									postalCode:'',
									isDefault:res.data.ad_status=='0'?true:false,
								}
								that.addressInfo = addressInfo;
								console.log(that.addressInfo)
							} else {
								that.addressdetail = ''
							}
						});
					},
					onSave(val) {
						console.log(val)
						var parm = {
							id: addressid,
							ad_area: val.areaCode, //区
							ad_city: val.city, //市
							ad_province: val.province, //省
							ad_consignee: val.name, //收货人
							ad_detail_address: val.addressDetail, //详细地址
							ad_phone: val.tel, //手机号码
							ad_status: val.isDefault ? '0' : '1', //默认地址
							create_time: '',
							update_time: '',
						}
						cfg.majaxAction("saveOrUpdateAddress", parm, function(res) {
							console.log(parm.ad_status)
							window.location.href = "address.html?orderType="+qsd.orderType;
						});
						vant.Toast('save');
						console.log(val)
					},
				},
				filters: {

				}
			})
		</script>
	</body>
</html>
